package com.jxkj.controller;

import com.jxkj.entity.Student;
import com.jxkj.repository.RedisRepository;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能描述：
 *
 * @author wcx
 * @version 1.0
 */
@RestController
public class TestController {

    @Autowired
    private RedisRepository redisRepository;

    @GetMapping("/getRedisInfo")
    public Object getRedisInfo(){
        List<Object> users = redisRepository.getList("students");
        return users;
    }

    @PostMapping("/saveRedisInfo")
    public Object saveRedisInfo(){
        List<Student> students = new ArrayList<>();
        Student student1 = new Student(1L, "zyy", 18);
        Student student2 = new Student(2L, "wcx", 19);
        students.add(student1);
        students.add(student2);
        ListOperations<String, Student> students1 = redisRepository.setList("students", students);
        return students1;
    }
}
